/* 
 * File:   IndexHandler.h
 * Author: taylor
 *
 * Created on November 7, 2012, 2:31 PM
 */

#ifndef INDEXHANDLER_H
#define	INDEXHANDLER_H

#include<string>
#include "TreeInterface.h"
#include "Term.h"
#include "AVLTreeAdapter.h"
#include "HashTableAdapter.h"
#include "Document.h"

class IndexHandler {
public:
    /**
     * If nothing is specified, use an AVL tree by default
     */
    IndexHandler();
    /**
     * Constructor allowing selection of an AVLTree or HashTable
     * @param type char representing structure type a=AVL, b=HashTable
     */
    IndexHandler(char type);
    
    
    void addTermsFromDocument(Document d);
    
    /**
     * Check if a term exists in the tree and if not, insert it
     * @param term string to add as a term
     * @return ptr to newly created term or the old term that was found
     */
    Term* insert(string term);
    /**
     * Search for a term in the current tree
     * @param query
     * @return ptr to Term object
     */
    Term* search(string query);
    /**
     * Function to write the tree or hash table to a file
     */
    void writeIndexToFile(string filePath);
    /**
     * Function to read the tree index from a file and back into the structure
     */
    void readIndexFromFile(string filePath);
    
    /**
     * Take a search query, parse it and output results
     * @param query
     */
    void outputRawSearch(string query);
    
private:
    TreeInterface* _tree;
};

#endif	/* INDEXHANDLER_H */

